﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using CoiffeurProject.Utils;
using CoiffeurProject.DBMS;
using CoiffeurProject.UserControls;

namespace CoiffeurProject.Screens
{
    public partial class MainWindow : Window
    {
        DispatcherTimer timer;
        Database db;

        public MainWindow()
        {
            InitializeComponent();

            StartTimer();

            for (int i = 0; i < 6; i++)
            { 
                var agenda_page = new AgendaPage(0,i);
                agenda_pages_grid.Children.Add(agenda_page.MainContainer);
            }

            var searchBox = new SearchBar(new Thickness(1450, 0, 0, 0), 0, 0);
            main_container.Children.Add(searchBox.MainContainer);

            db = new Database();

            main_container.Children.Add(MainTicketButtonFactory.GetCalendarPanel(1,0));
            main_container.Children.Add(MainTicketButtonFactory.GetCustomersPanel(this, 1, 0, db));
            main_container.Children.Add(MainTicketButtonFactory.GetServicesPanel(1, 0));
            main_container.Children.Add(MainTicketButtonFactory.GetWarehousePanel(1, 0));
            main_container.Children.Add(MainTicketButtonFactory.GetEmployeesPanel(this, 1, 0, db));
            main_container.Children.Add(MainTicketButtonFactory.GetAccountingPanel(1, 0));
        }

        private void StartTimer()
        {
            var h = DateTime.Now.Hour; var m = DateTime.Now.Minute;
            mn_time.Content = (h < 10 ? "0" + h : h.ToString()) + ":" + (m < 10 ? "0" + m : m.ToString());
            mn_month.Content = DateTime.Now.MonthToString();
            mn_day.Content = DateTime.Now.DayToString();
            mn_day_n.Content = DateTime.Now.Day;

            timer = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 1, 0);
            timer.Tick += new EventHandler(timer_Tick);

            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            var h = DateTime.Now.Hour; var m = DateTime.Now.Minute;
            mn_time.Content = (h < 10 ? "0" + h : h.ToString()) + ":" + (m < 10 ? "0" + m : m.ToString());
            mn_month.Content = DateTime.Now.MonthToString();
            mn_day.Content = DateTime.Now.DayToString();
            mn_day_n.Content = DateTime.Now.Day;
        }

        private void OnOff_Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Button_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string packUri = "pack://application:,,,/CoiffeurProject;component/Images/Main/on_off_button_pressed.png";
            close_button_icon.Source = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource;
        }

        private void close_button_icon_MouseLeave(object sender, MouseEventArgs e)
        {
            string packUri = "pack://application:,,,/CoiffeurProject;component/Images/Main/on_off_button.png";
            close_button_icon.Source = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource;
        }
    }
}
